﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UIT_CV_Management
{
    public partial class UserControlQuaTrinhHDKHKT : UserControl
    {
        bool isEveryThingOK = false;
        bool isTenDoAnOK = false;
        bool isThoiGianOK = true;
        bool isKetQuaOK = false;
        bool isNoiCongTacOK = false;

        //object
        QuaTrinhHoatDongKHKT quaTrinhHDKHKT;

        public UserControlQuaTrinhHDKHKT()
        {
            InitializeComponent();
            // hide all
            this.hideAllErrorImage();

            // init language
            this.initLanguage();
        }

        private void initLanguage()
        {
            lblTenDoAn.Text = Language._("QUATRINHHDKHKT_FORM_TENDOAN_LBL");
            lblThoiGIan.Text = Language._("QUATRINHHDKHKT_FORM_THOIGIAN_LBL");
            lblKetQua.Text = Language._("QUATRINHHDKHKT_FORM_KETQUA_LBL");
            lblNoiCongTac.Text = Language._("QUATRINHHDKHKT_FORM_NOICONGTAC_LBL");
        }

        private void hideAllErrorImage()
        {
            pictureBoxTenDoAn.Visible = false;
            pictureBoxKetQua.Visible = false;
            pictureBoxNoiCongTac.Visible = false;
        }

        private void txbTenDoAn_Validating(object sender, CancelEventArgs e)
        {
            bool isHasError = false;

            if (txbTenDoAn.Text.Trim() == "")
                isHasError = true;

            if (isHasError)
            {
                isTenDoAnOK = false;
                
                // change NoiSinh's background color to Tomato
                // Add UserTip
                txbTenDoAn.BackColor = Color.Tomato;
                utpTip.Value = Language._("QUATRINHHDKHKT_FORM_TIP_TENDOAN_NULL");
                utpTip.Visible = true;
                pictureBoxTenDoAn.Visible = false;
            }
            else
            {
                isTenDoAnOK = true;
                txbTenDoAn.BackColor = Color.White;
                pictureBoxTenDoAn.Visible = true;
                utpTip.Visible = false;
            }
        }

        private void txbKetQua_Validating(object sender, CancelEventArgs e)
        {
            bool isHasError = false;
            float outResult;

            // check Luong is numberic
            if (!float.TryParse(txbKetQua.Text, out outResult))
            {
                isHasError = true;
            }
            else
                if ((outResult < 0) || (outResult > 10))
                {
                    isHasError = true;
                }
            if (isHasError)
            {
                isKetQuaOK = false;
                
                // change NoiSinh's background color to Tomato
                // Add UserTip
                txbKetQua.BackColor = Color.Tomato;
                utpTip.Value = Language._("HOATDONGKHKT_FORM_TIP_KETQUA_NULL");
                utpTip.Visible = true;
                pictureBoxKetQua.Visible = false;
            }
            else
            {
                isKetQuaOK = true;
                txbKetQua.BackColor = Color.White;
                pictureBoxKetQua.Visible = true;
                utpTip.Visible = false;
            }
        }

        private void txbNoiCongTac_Validating(object sender, CancelEventArgs e)
        {
            bool isHasError = false;

            if (txbNoiCongTac.Text.Trim() == "")
                isHasError = true;

            if (isHasError)
            {
                isNoiCongTacOK = false;
                
                // change NoiSinh's background color to Tomato
                // Add UserTip
                txbNoiCongTac.BackColor = Color.Tomato;
                utpTip.Value = Language._("QUATRINHHDKHKT_FORM_TIP_NOICONGTAC_NULL");
                utpTip.Visible = true;
                pictureBoxNoiCongTac.Visible = false;
            }
            else
            {
                isNoiCongTacOK = true;
                txbNoiCongTac.BackColor = Color.White;
                pictureBoxNoiCongTac.Visible = true;
                utpTip.Visible = false;
            }
        }

        public bool isQuaTrinhHDKHKTOK()
        {
            //Validate
            txbTenDoAn_Validating(txbTenDoAn, null);
            txbKetQua_Validating(txbKetQua, null);
            txbNoiCongTac_Validating(txbNoiCongTac, null);

            isEveryThingOK = isTenDoAnOK && isThoiGianOK && isKetQuaOK && isNoiCongTacOK;
            return isEveryThingOK;
        }
        public QuaTrinhHoatDongKHKT getQuaTrinhHDKHKT()
        {
            if (this.isQuaTrinhHDKHKTOK())
            {
                quaTrinhHDKHKT = new QuaTrinhHoatDongKHKT(txbTenDoAn.Text, dtpThoiGIan.Value, txbNoiCongTac.Text, float.Parse(txbKetQua.Text));
            }
            return quaTrinhHDKHKT;
        }

    }
}
